home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
029a
/
masview.zip
/
TTT3.C
< prev
next >
Wrap
Text File
|
1991-10-23
|
1KB
|
47 lines
/* ttt3.c - check for game over */
#include "stdio.h"
#include "ttt.h"
game_over( bd ) /* check and return true or false */
char bd[ 3 ][ 3 ];
{
int x, y;
if ( winner( bd ) )
return( TRUE );
for ( x = 0; x < 3; ++x )
for ( y = 0; y < 3; ++y )
if ( bd[ x ][ y ] == EMPTY )
return( FALSE );
return( TRUE );
}
winner( bd ) /* check for a winner on bd[][], return true or false */
char bd[ 3 ][ 3 ];
{
int x;
for ( x = 0; x < 3; ++x )
{
if ( bd[ x ][ 0 ] != EMPTY /* winner across? */
&& bd[ x ][ 0 ] == bd[ x ][ 1 ]
&& bd[ x ][ 1 ] == bd[ x ][ 2 ] )
return( TRUE );
if ( bd[ 0 ][ x ] != EMPTY /* winner up and down? */
&& bd[ 0 ][ x ] == bd[ 1 ][ x ]
&& bd[ 1 ][ x ] == bd[ 2 ][ x ] )
return( TRUE );
}
if ( bd[ 1 ][ 1 ] != EMPTY ) /* winner diagonally? */
{
if ( bd[ 0 ][ 0 ] == bd[ 1 ][ 1 ]
&& bd[ 1 ][ 1 ] == bd[ 2 ][ 2 ] )
return( TRUE );
if ( bd[ 0 ][ 2 ] == bd[ 1 ][ 1 ]
&& bd[ 1 ][ 1 ] == bd[ 2 ][ 0 ] )
return( TRUE );
}
return( FALSE ); /* no winner yet */
}